Ccay.Module.define("Ccay.example.ui.igird.managerFunction", function (page, $S) {
	page.ready = function(){
		var linkBtns = [
			{text: "${id}", click: page.operateTest}
		];
		var gridOption = {
			height: 300,
			editMode: true,
			wrapHead: false,
		    columns: [
		    	{columnType:'select', multi:true},
		    	{width: 70, freezeable: true, columnType:'operate', btns:linkBtns},
		 		{field: 'name', width:90, header: "ccay.common.label.name", freezeable: true, rule: {required: true}},
		 		{field: 'sex', width:70, header: "sSex", type: 'bool', format: {isIcon: true}},
		 		{field: 'age', width:70, header: "sAge", type: 'integer', rule: {range: [16, 80]}},
		 		{field: 'birthday', width:110, header: "sBirthday", type: 'date'},
		 		{field: 'blog', width:200, header: "sBlog", showTip:true},
		 		{field: 'lastUpdateDate', width:130, header: "ccay.common.label.lastUpdatedDate", type: 'datetime', editable: false, content: "${#getLastTime(lastUpdateDate)}"}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/${pageSize}/${curPage}/${orderBy}'
			},
		    operation: {
		    	search: {
		    		btn: '#btnSearch',
					panel: '#searchForm'
		    	},
		    	del: {
		    		btn: '#btnDel',
		    		undoBtn: '#btnUndoDel'
		    	},
		    	insert: {
		    		btn: '#btnAdd',
		    		copy: true,
		    		clear: ['id', 'name', 'lastUpdateDate'],
		    		defaultRow:{ sex: 1, blog: 'http://', tuition: '0'}
		    	},
		    	save: {
		    		btn: '#btnSave',
		    		ajax: {
		    			url: "services/ccay/demo/student/batch"
		    		}
		    	}
		    }
		};
		
		$S("#managerFunctionDemo").ccayTab();
		
		//点击tab头后，才加载数据，只第一次生效
		$S("li[tabid='tab2']").one("click", function () {
			$S("#iStudent").igrid(gridOption);
		});
	};
	
	getLastTime = function(data){
		return Ccay.Format.toDateBefore(data && data.getUTCTime());
	};
	
	page.operateTest = function (value) {
		alert(Ccay.DataHelper.toJsonStr(value));
	};
	
	page.openDemo = function(tabId){
		$S("#managerFunctionDemo").getCcayTabManager().selectItem(tabId);
		$S("li[tabid='" + tabId + "']").click();
	};
	page.openNewWindow = function (data){
		Ccay.UI.dialog("ccay/example/ui/igrid/showData.html","showData",{width:800,height:500,callback:function(){$("#showTestData").val(Ccay.DataHelper.toJsonStr(data))}});
	}
});